<div class="layui-fluid layui-anim febs-anim" id="febs-obj" lay-title="业务办理事项管理">
    <div class="layui-row febs-container">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body febs-table-full">
                    <form class="layui-form layui-table-form" lay-filter="obj-table-form">
                        <div class="layui-row">
                            <div class="layui-col-md10">
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">部门</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="departName" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">主项</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="mainItemName" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">子项</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="sumItemName" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">业务办理名称</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="name" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">事项类别</label>
                                        <div class="layui-input-inline">
                                            <select name="itemType" >
                                                <option value=""></option>
                                                <option value="公共服务">公共服务</option>
                                                <option value="行政裁决">行政裁决</option>
                                                <option value="行政给付">行政给付</option>
                                                <option value="行政检查">行政检查</option>
                                                <option value="行政奖励">行政奖励</option>
                                                <option value="行政确认">行政确认</option>
                                                <option value="行政许可">行政许可</option>
                                                <option value="行政征收">行政征收</option>
                                                <option value="其他职权">其他职权</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">办理地址</label>
                                        <div class="layui-input-inline">
                                            <select id="addressType" name="addressType" >
                                                <option value=""></option>
                                                <option value="大厅">大厅</option>
                                                <option value="分厅">分厅</option>
                                                <option value="大厅/分厅">大厅/分厅</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">服务对象</label>
                                        <div class="layui-input-inline">
                                            <select id="serviceObject" name="serviceObject" >
                                                <option value=""></option>
                                                <option value="个人">个人</option>
                                                <option value="法人">法人</option>
                                                <option value="个人/法人">个人/法人</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">即办事项</label>
                                        <div class="layui-input-inline">
                                            <select name="immediately" >
                                                <option value=""></option>
                                                <option value="1">是</option>
                                                <option value="0">否</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">凭身份证办理：</label>
                                        <div class="layui-input-inline">
                                            <select name="needCard" >
                                                <option value=""></option>
                                                <option value="1">是</option>
                                                <option value="0">否</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">通办事项：</label>
                                        <div class="layui-input-inline">
                                            <select name="allCityHandle" >
                                                <option value=""></option>
                                                <option value="1">是</option>
                                                <option value="0">否</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">最多跑一次：</label>
                                        <div class="layui-input-inline">
                                            <select  name="atMostOnce" >
                                                <option value=""></option>
                                                <option value="1">是</option>
                                                <option value="0">否</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">零跑动：</label>
                                        <div class="layui-input-inline">
                                            <select name="zeroRun" >
                                                <option value=""></option>
                                                <option value="1">是</option>
                                                <option value="0">否</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">是否网办：</label>
                                        <div class="layui-input-inline">
                                            <select name="onlineCheck" >
                                                <option value=""></option>
                                                <option value="1">是</option>
                                                <option value="0">否</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">办理系统</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="bussSystem" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>

                                </div>
                            </div>
                            <div class="layui-col-md2 layui-col-sm12 layui-col-xs12 table-action-area">
                                <div class="layui-btn layui-btn-sm layui-btn-primary table-action" id="query">
                                    <i class="layui-icon">&#xe848;</i>
                                </div>
                                <div class="layui-btn layui-btn-sm layui-btn-primary table-action" id="reset">
                                    <i class="layui-icon">&#xe79b;</i>
                                </div>
                                <div class="layui-btn layui-btn-sm layui-btn-primary table-action action-more">
                                    <i class="layui-icon">&#xe875;</i>
                                </div>
                            </div>
                        </div>
                    </form>
                    <button class="layui-btn  layui-btn-sm layui-btn-primary" id="importExcel">
                        <i class="layui-icon">&#xe7a8;</i> 批量导入
                    </button>
                    <table lay-filter="objTable" lay-data="{id: 'objTable'}"></table>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/html" id="obj-option">
    <a lay-event="detail" ><i
                class="layui-icon febs-edit-area febs-green">&#xe7a5;</i></a>
    <a lay-event="edit" ><i
                class="layui-icon febs-edit-area febs-blue">&#xe7a4;</i></a>
    <a lay-event="del" ><i class="layui-icon febs-edit-area febs-red">&#xe7f9;</i></a>
</script>
<script type="text/html" id="immediately">
    {{#
    var immediately = {
    1: {title: '是'},
    0: {title: '否'},
    '': {title: ''}
    }[d.immediately];
    }}
    <span>{{ immediately.title }}</span>
</script>
<script type="text/html" id="needCard">
    {{#
    var needCard = {
    1: {title: '是'},
    0: {title: '否'},
    '': {title: ''}
    }[d.needCard];
    }}
    <span>{{ needCard.title }}</span>
</script>
<script type="text/html" id="allCityHandle">
    {{#
    var allCityHandle = {
    1: {title: '是'},
    0: {title: '否'},
    '': {title: ''}
    }[d.allCityHandle];
    }}
    <span>{{ allCityHandle.title }}</span>
</script>
<script type="text/html" id="atMostOnce">
    {{#
    var atMostOnce = {
    1: {title: '是'},
    0: {title: '否'},
    '': {title: ''}
    }[d.atMostOnce];
    }}
    <span>{{ atMostOnce.title }}</span>
</script>
<script type="text/html" id="zeroRun">
    {{#
    var zeroRun = {
    1: {title: '是'},
    0: {title: '否'},
    '': {title: ''}
    }[d.zeroRun];
    }}
    <span>{{ zeroRun.title }}</span>
</script>
<script type="text/html" id="onlineCheck">
    {{#
    var onlineCheck = {
    1: {title: '是'},
    0: {title: '否'},
    '': {title: ''}
    }[d.onlineCheck];
    }}
    <span>{{ onlineCheck.title }}</span>
</script>
<script data-th-inline="none" type="text/javascript">
    layui.use(['dropdown', 'jquery', 'laydate', 'form', 'table', 'febs', 'treeSelect','upload'], function () {
        var $ = layui.jquery,
            laydate = layui.laydate,
            upload = layui.upload,
            febs = layui.febs,
            form = layui.form,
            table = layui.table,
            dropdown = layui.dropdown,
            $view = $('#febs-obj'),
            $query = $view.find('#query'),
            $reset = $view.find('#reset'),
            $searchForm = $view.find('form'),
            sortObject = {field: 'createTime', type: null},
            tableIns;

        form.render();

        initTable();

        laydate.render({
            elem: '#createTime',
            range: true,
            trigger: 'click'
        });

        dropdown.render({
            elem: $view.find('.action-more'),
            click: function (name, elem, event) {
                var checkStatus = table.checkStatus('objTable');
                if (name === 'add') {
                    febs.modal.open('新增', 'hallItem/add', {
                        btn: ['提交', '重置'],
                        area: $(window).width() <= 750 ? '95%' : '50%',
                        yes: function (index, layero) {
                            $('#obj-add').find('#submit').trigger('click');
                        },
                        btn2: function () {
                            $('#obj-add').find('#reset').trigger('click');
                            return false;
                        }
                    });
                }
                if (name === 'delete') {
                    if (!checkStatus.data.length) {
                        febs.alert.warn('请选择需要删除的记录');
                    } else {
                        febs.modal.confirm('删除', '确定删除该条记录？', function () {
                            var objIds = [];
                            layui.each(checkStatus.data, function (key, item) {
                                objIds.push(item.id)
                            });
                            deleteobjs(objIds.join(','));
                        });
                    }
                }
            },
            options: [{
                name: 'add',
                title: '新增'
            }, {
                name: 'delete',
                title: '删除'
            }]
        });


        table.on('tool(objTable)', function (obj) {
            var data = obj.data,
                layEvent = obj.event;
            if (layEvent === 'del') {
                febs.modal.confirm('删除', '确定删除该条记录？', function () {
                    deleteobjs(data.id);
                });
            }
            if (layEvent === 'edit') {
                febs.modal.open('修改', 'hallItem/update/' + data.id, {
                    area: $(window).width() <= 750 ? '90%' : '50%',
                    btn: ['提交', '取消'],
                    yes: function (index, layero) {
                        $('#obj-update').find('#submit').trigger('click');
                    },
                    btn2: function () {
                        layer.closeAll();
                    }
                });
            }
        });

        table.on('sort(objTable)', function (obj) {
            sortObject = obj;
            tableIns.reload({
                initSort: obj,
                where: $.extend(getQueryParams(), {
                    field: obj.field,
                    order: obj.type
                })
            });
        });

        $query.on('click', function () {
            var params = $.extend(getQueryParams(), {field: sortObject.field, order: sortObject.type});
            tableIns.reload({where: params, page: {curr: 1}});
        });

        $reset.on('click', function () {
            $searchForm[0].reset();
            tableIns.reload({where: getQueryParams(), page: {curr: 1}});
        });
        $view.on('click', '#importExcel', function () {

        });
        var uploadInst = upload.render({
            elem: '#importExcel' //绑定元素
            ,url: ctx+'hallItem/fileUpload' //上传接口
            ,accept: 'file'
            ,exts:'xls|xlsx'
            ,done: function(res){
                //上传完毕回调
                if(res.code=200){
                    var params = $.extend(getQueryParams(), {field: sortObject.field, order: sortObject.type});
                    tableIns.reload({where: params, page: {curr: 1}});
                    febs.alert.success('批量上传成功');
                }else{
                    febs.alert.success('批量上传失败');
                }

            }
            ,error: function(){
                //请求异常回调
            }
        });
        function initTable() {
            tableIns = febs.table.init({
                elem: $view.find('table'),
                id: 'objTable',
                url: ctx + 'hallItem/list',
                cols: [[
                    {type: 'checkbox'},
                    {field: 'name', title: '业务办理名称'},
                    {field: 'sumItemName', title: '子项'},
                    {field: 'mainItemName', title: '主项'},
                    {field: 'departName', title: '部门'},
                    {field: 'itemType', title: '事项类别'},
                    {field: 'addressType', title: '办理地址'},
                    {field: 'serviceObject', title: '服务对象'},
                    /*{field: 'immediately', title: '即办事项'},*/
                    {title: '即办事项', templet: '#immediately'},
                    {title: '凭身份证办理', templet: '#needCard'},
                    //{field: 'needCard', title: '凭身份证办理'},
                    //{field: 'allCityHandle', title: '通办事项'},
                    {title: '通办事项', templet: '#allCityHandle'},
                    //{field: 'atMostOnce', title: '最多跑一次'},
                    {title: '最多跑一次', templet: '#atMostOnce'},
                   // {field: 'zeroRun', title: '零跑动'},
                    {title: '零跑动', templet: '#zeroRun'},
                  //  {field: 'onlineCheck', title: '是否网办'},
                    {title: '是否网办', templet: '#onlineCheck'},
                    {field: 'bussSystem', title: '办理系统'},
                    /*{field: 'level', title: '实施层级'},
                    {field: 'selfHelp', title: '支持自助终端办理'},
                    {field: 'appointment', title: '支持预约办理'},
                    {field: 'express', title: '支持物流快递'},
                    {field: 'investItem', title: '是否投资事项'},
                    {field: 'agentService', title: '涉及中介服务'},
                    {field: 'collectionMethod', title: '办理结果领取方式'},*/
                    {title: '操作', toolbar: '#obj-option', minWidth: 140}
                ]]
            });
        }

        function getQueryParams() {
            return {
                    name: $searchForm.find('input[name="name"]').val().trim(),
                    mainItemName: $searchForm.find('input[name="mainItemName"]').val().trim(),
                    departName: $searchForm.find('input[name="departName"]').val().trim(),
                    sumItemName: $searchForm.find('input[name="sumItemName"]').val().trim(),
                    bussSystem: $searchForm.find('input[name="bussSystem"]').val().trim(),
                    itemType:  $searchForm.find('select[name="itemType"]').val(),
                    addressType:  $searchForm.find('select[name="addressType"]').val(),
                    serviceObject: $searchForm.find('select[name="serviceObject"]').val(),
                    immediately:$searchForm.find('select[name="immediately"]').val(),
                    needCard:  $searchForm.find('select[name="needCard"]').val(),
                    allCityHandle:  $searchForm.find('select[name="allCityHandle"]').val(),
                    atMostOnce:  $searchForm.find('select[name="atMostOnce"]').val(),
                    zeroRun:  $searchForm.find('select[name="zeroRun"]').val(),
                    onlineCheck:  $searchForm.find('select[name="onlineCheck"]').val(),

            };
        }

        function deleteobjs(objIds) {
            febs.get(ctx + 'hallItem/delete/' + objIds, null, function () {
                febs.alert.success('删除成功');
                $query.click();
            });
        }
    })
</script>